import java.util.PriorityQueue;

public class Solution {
    class Car {
        int index;
        double time;
        public Car(int index,double time) {
            this.index = index;
            this.time = time;
        }
    }
    public int carFleet(int target, int[] position, int[] speed) {
        if (position.length == 0) {
            return -1;
        }
        PriorityQueue<Car> prioriQueue = new PriorityQueue<>((o1, o2) -> position[o2.index]- position[o1.index]);
        for (int i = 0; i < position.length; i++) {
            double t = (double) (target - position[i]) / speed[i];
            Car car = new Car(i,t);
            prioriQueue.offer(car);
        }
        int count = 0;
        while (!prioriQueue.isEmpty()) {
            Car cur = prioriQueue.poll();
            while (!prioriQueue.isEmpty() && (cur.time >= prioriQueue.peek().time)) {
                prioriQueue.poll();
            }
            count++;

        }
        return count;
    }

    public void sortColors(int[] nums) {
        int index = 0;
        for(int i = 0;i < nums.length ;i++) {
            if(nums[i] == 0) {
                swap(nums,i,index);
                index++;
            }
        }
        for(int i = 0;i < nums.length ;i++) {
            if(nums[i] == 1) {
                swap(nums,i,index);
                index++;
            }
        }
    }

    public void swap(int[] nums,int i,int index) {
        int tmp = nums[i];
        nums[i] = nums[index];
        nums[index] = tmp;
    }

}
